<admintpl file="header" />
<style>
/* .qlistbox, table { */
/* 	overflow-y: scroll; */
/* } */
h2{
	text-align: center;
}
.qlistbar{
	border:1px solid #ccc;
	padding:10px;
	background-color: #ccc;
}
.qlistbar div{
	border:1px dotted #ccc;
	padding:10px;
	background-color: #fff;
}
.qlistbox{	
	padding: 10px 0 10px 0;	
}
.qlisthead {
	padding: 0 0 0 0;
}
.trsel {
	background-color: #DFEBF2;
}
.q_options{
	display:block;
}
.q_item{
	border:1px solid #ccc;
	padding:10px;
	margin-top:10px;
}
.q_options{
	padding:10px 10px;
}
.q_options ul li{
	list-style-type: none;
}
.q_item_container{
	background-color: #eee;
	list-style-type: none;
}
.q_content{	
	font-weight: bold;	
	border:1px dotted #ccc;
	padding:10px;
	background-color: #fff;
}
.q_answer_box{
	padding:5px;
	border:1px dotted #ccc;
	background-color: #ecc;	
}
.q_answer_box div{
	margin:10px;
}
.qlistbody{
	padding:0;
	margin:0;
}
</style>
</head>
<body>
	<div class="row-fluid">
		<div class="span12 wrap">
			<h2>{$paper.paper_name}</h2>
			<div style="margin:10px 0;">
				
				<volist name="ques_type_lite_arr" id="paper_type">
				<neq name="ques_type_arr[$paper_type]['ques_list']|sp_arr_count" value="0">
				<button type="button" onclick="javascript:location.href='#qlist_{$paper_type}'">{++$tmp_index}.{$question_types[$paper_type]}({$ques_type_arr[$paper_type]['ques_list']|sp_arr_count})</button>
				</neq>
				</volist>
			</div>
			<div class="qlistbar">
				<div>	</div>							
			</div>
			<foreach name="ques_type_arr" item="vo" key="paper_type">			
			<if condition="strlen($ques_type_arr[$paper_type]['ques_list'])">
			<div class="qlistbox" id="qlist_{$paper_type}">
				<div class="qlisthead">
					<b>{$ques_type_index_name[$ques_type_index++]}、{$question_types[$paper_type]}（共计<span id="ques_sel_count">{$ques_type_arr[$paper_type]['ques_list']|sp_arr_count}</span>题）</b>
				</div>				
				<ul class="qlistbody">
					<foreach name="ques_list" item="vo">
					<if condition="in_array($vo['id'],explode(',',$ques_type_arr[$paper_type]['ques_list']))">
					<li class="q_item_container">
					<div class="q_item">
						<div class="q_content">{++$ques_index}.（{$vo.ques_score}分ID:{$vo.id}） {$vo.ques_content|sp_remove_tag_p}</div>
						<if condition="$paper_type!=3 and $paper_type!=5">
						<div class="q_options">
							<ul>
								<volist name=":unserialize($vo['options'])" id="ques">
								<li><label class="{$type_control[$paper_type]}"><input type="{$type_control[$paper_type]}" value="{$i+1}" id="ques_{$vo.id}" name="ques_{$vo.id}"/><?php echo ($paper_type<=2?$question_opts[$i].'. ':''); ?> {$ques}</label></li>
								</volist>
							</ul>
						</div>
						</if>
						<div class="q_answer_box">
							<div class="q_answer_result">参考答案：<span>{$vo.answer|sp_get_type_option=$paper_type,###}</span></div>
							<div class="q_answer_guide">答案解析：<span>{$vo.ques_guide}</span></div>						
						</div>
					</div>
					</li>
					
					</if>
					</foreach>
				</ul>
			</div>
			
			</if>
			</foreach>
		</div>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
	<script src="__PUBLIC__/js/cookie.js"></script>
	<SCRIPT LANGUAGE="JavaScript">	
	$(function() {
		var ques_json='';
// 		<foreach name="ques_type_arr" item="vo" key="paper_type">
// 		<notempty name="vo.ques_list">init_ques_list({$vo.ques_list});</notempty>
// 		</foreach>
		//init_ques_list();
		function init_ques_list(){
			$('.qlistbody').empty();
			var ques_count=0;
			for(var o in ques_json){
				var td1=ques_json[o].id;
				var td2=ques_json[o].ques_content;
				console.log(unserialize(ques_json[o].options));
				var td3=ques_json[o].options;//unserialize(ques_json[o].options).length;
				var td4=ques_json[o].id;
				var div=["<div class=\"q_item_container\">",
				"<div class=\"q_item\" data-id=\"",td1,"\">",
				"<div class=\"q_content\">",o+1,"，编号",td1,"-",td4,"-",td2,"<br />",td3,"</div>",
				"</div>",
				"</div>"].join("");
				$('.qlistbody').append(div);
				ques_count++;
			 }
			 $("#ques_sel_count").text(ques_count);
			 //alert(current_ques_ids_arr.join(','));			
		}
	});
	</SCRIPT>

	<script>
// 		$(".sortable").sortable({
// 	      placeholder: "ui-state-highlight"
// 	    });
// 		$(".sortable").disableSelection();
		
// 		function refersh_window() {
// 			var refersh_time = getCookie('refersh_time');
// 			if (refersh_time == 1) {
// 				window.location = "{:U('Questions/queslist',$formget)}";
// 			}
// 		}
// 		setInterval(function() {
// 			refersh_window();
// 		}, 2000);
		$(function() {
			setCookie("refersh_time", 0);
			Wind.use('validate', 'ajaxForm', 'artDialog', function() {
				var form = $('form.js-ajax-forms');
				//ie处理placeholder提交问题
				if ($.browser && $.browser.msie) {
					form.find('[placeholder]').each(function() {
						var input = $(this);
						if (input.val() == input.attr('placeholder')) {
							input.val('');
						}
					});
				}
				var formloading = false;
				//表单验证开始
				form.validate({
					//是否在获取焦点时验证
					onfocusout : false,
					//是否在敲击键盘时验证
					onkeyup : false,
					//当鼠标掉级时验证
					onclick : false,
					//验证错误
					showErrors : function(errorMap, errorArr) {
						//errorMap {'name':'错误信息'}
						//errorArr [{'message':'错误信息',element:({})}]
						try {
							$(errorArr[0].element).focus();
							art.dialog({
								id : 'error',
								icon : 'error',
								lock : true,
								fixed : true,
								background : "#CCCCCC",
								opacity : 0,
								content : errorArr[0].message,
								cancelVal : '确定',
								cancel : function() {
									$(errorArr[0].element).focus();
								}
							});
						} catch (err) {
						}
					},
					//验证规则
					rules : {
						paper_name : {
							required : true
						},
						paper_type : {
							required : true
						},
						paper_term : {
							required : true
						},
						paper_score : {
							required : true
						},
						paper_pass_score : {
							required : true
						},
//		 				opt : {
//		 					required : $('#ques_type').val()==1||$('#ques_type').val()==4
//		 				},
//		 				'opts[]' : {
//		 					required : $('#ques_type').val()==2
//		 				},
						
					},
					//验证未通过提示消息
					messages : {
						ques_term : {
							required : '请选择考题分类'
						},
						ques_type : {
							required : '请选择题型'
						},
						ques_score : {
							required : '请填写试题分数'
						},
						ques_content : {
							required : '请填写题干',
							editorcontent : '内容不能为空'
						}			
						
					},
//		 			errorPlacement: function (error, element) { //指定错误信息位置
//		 				if (element.is(':radio') || element.is(':checkbox')) {
//		 					var eid = element.attr('name');
//		 					error.appendTo(element.parent());
//		 				} else {
//		 					error.insertAfter(element);
//		 				}
//		 			},
					//给未通过验证的元素加效果,闪烁等
					highlight : false,
					//是否在获取焦点时验证
					onfocusout : false,
					//验证通过，提交表单
					submitHandler : function(forms) {
						if (formloading)
							return;
						$(forms).ajaxSubmit({
							url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
							dataType : 'json',
							beforeSubmit : function(arr, $form, options) {
								formloading = true;
							},
							success : function(data, statusText, xhr, $form) {
								formloading = false;
								if (data.status) {
									setCookie("refersh_time", 1);
									//添加成功
									Wind.use("artDialog", function() {
										art.dialog({
											id : "succeed",
											icon : "succeed",
											fixed : true,
											lock : true,
											background : "#CCCCCC",
											opacity : 0,
											content : data.info,
											button : [ {
												name : '继续添加？',
												callback : function() {
													reloadPage(window);
													return true;
												},
												focus : true
											}, {
												name : '返回列表页',
												callback : function() {
													location = "{:U('Questions/index')}";
													return true;
												}
											} ]
										});
									});
								} else {
									artdialog_alert(data.info);
								}
							}
						});
					}
				});
			});
		});
	</script>
</body>
</html>